package com.ruoyi.web.hb.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.hb.domain.ChannelBuoy;
import com.ruoyi.web.hb.domain.ChannelBuoyInfos;
import com.ruoyi.web.hb.service.IChannelBuoyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 航标基础数据Controller
 *
 * @author ruoyi
 * @date 2025-09-19
 */
@RestController
@RequestMapping("/system/buoy")
public class ChannelBuoyController extends BaseController
{
    @Autowired
    private IChannelBuoyService channelBuoyService;

    /**
     * 查询航标基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:buoy:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelBuoy channelBuoy)
    {
        startPage();
        List<ChannelBuoy> list = channelBuoyService.selectChannelBuoyList(channelBuoy);
        return getDataTable(list);
    }

    @GetMapping("/get")
    public ChannelBuoyInfos getChannelBuoyInfo(ChannelBuoy channelBuoy)
    {
        ChannelBuoyInfos channelBuoyInfos = channelBuoyService.selectChannelBuoyInfo(channelBuoy);
        return channelBuoyInfos;
    }

    /**
     * 导出航标基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:buoy:export')")
    @Log(title = "航标基础数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChannelBuoy channelBuoy)
    {
        List<ChannelBuoy> list = channelBuoyService.selectChannelBuoyList(channelBuoy);
        ExcelUtil<ChannelBuoy> util = new ExcelUtil<ChannelBuoy>(ChannelBuoy.class);
        util.exportExcel(response, list, "航标基础数据数据");
    }

    /**
     * 获取航标基础数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:buoy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(channelBuoyService.selectChannelBuoyById(id));
    }

    /**
     * 新增航标基础数据
     */
    @PreAuthorize("@ss.hasPermi('system:buoy:add')")
    @Log(title = "航标基础数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelBuoy channelBuoy)
    {
        return toAjax(channelBuoyService.insertChannelBuoy(channelBuoy));
    }

    /**
     * 修改航标基础数据
     */
    @PreAuthorize("@ss.hasPermi('system:buoy:edit')")
    @Log(title = "航标基础数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelBuoy channelBuoy)
    {
        return toAjax(channelBuoyService.updateChannelBuoy(channelBuoy));
    }

    /**
     * 删除航标基础数据
     */
    @PreAuthorize("@ss.hasPermi('system:buoy:remove')")
    @Log(title = "航标基础数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(channelBuoyService.deleteChannelBuoyByIds(ids));
    }

    /**
     * 删除航标基础数据
     */
    @PreAuthorize("@ss.hasPermi('system:buoy:remove')")
	@PostMapping("/getToken")
    public AjaxResult getToken() throws IOException {
        return AjaxResult.success(channelBuoyService.getNavigationList());
    }
}
